package view.macro
{
	import events.WorldEvent;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import model.macro.Territory;
	import model.macro.World;
	
	/**
	 */
	public class TerritorySprite extends Sprite
	{
		private var territory:Territory;
		private var world:World;
		private var _selected:Boolean;
		private var highlight:Shape;
		
		public function TerritorySprite(territory:Territory, world:World)
		{
			this.territory = territory;
			this.world = world;
			var color:int = 0x444444;
			if (territory.owner != null)
			{
				color = territory.owner.color;
			}
			
			highlight = new Shape();
			addChild(highlight);
			highlight.graphics.lineStyle(4, 0x00FFFF);
			highlight.graphics.drawCircle(0, 0, 15);
			
			graphics.beginFill(color);
			graphics.drawCircle(0, 0, 15);
			graphics.endFill();
			
			selected = false;
			
			addEventListener(MouseEvent.MOUSE_UP, onClick);
			addEventListener(MouseEvent.RIGHT_MOUSE_UP, onRightClickUp);
		}
		
		private function onRightClickUp(e:MouseEvent):void
		{
			trace("territory right clicked");
			world.dispatchEvent(new WorldEvent(WorldEvent.TERRITORY_RIGHT_CLICKED, null, territory));
		}
		
		private function onClick(e:MouseEvent):void
		{
			world.dispatchEvent(new WorldEvent(WorldEvent.TERRITORY_SELECTED, null, territory));
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function set selected(value:Boolean):void
		{
			_selected = value;
			highlight.visible = value;
		}
	
	}

}